# -*- coding: utf-8 -*-
# @Time    : 2021/4/5 20:48
# @Author  : Chen
# @Email   : 2356458272@qq.com
# @File    : 三乐购物1.py
# @Software: PyCharm
print("欢迎来到三乐购物".center(100,"*"))
yh = {'root':'123456'}
xb = {'root':'男'}
goods = {'F00001':{'gname':'苹果','price':1.2,'kc':100},'F00002':{'gname':'香蕉','price':1.5,'kc':88},
         'F00003':{'gname':'栗子','price':3.5,'kc':90},'F00004':{'gname':'叶罗丽娃娃','price':8.5,'kc':9}}
ygsp = {'F00001':{'gname':'苹果','price':1.2,'account':1}}
ls = 0
def ex(input):
    if input == 'exit':
        for bh, j in ygsp.items():
            print("编号:", bh, end=' ')
            print("商品名称：", j['gname'], end=' ')
            print("商品价格：", j['price'], end=' ')
            print("已购数量：", j['account'])
        print(ys)
        exit()
    else:
        pass
while 1:
    if input("输入exit退出") == 'exit':
        break
    print("请登录或者注册，输入1进入注册，输入2进行登录,输入3退出")
    while 1:
        try:
            xz = int(input("请选择："))
            if int(xz) == 1:
                print("注册界面".center(100, "*"))
                name = input("请输入用户名：")
                passward = input("请输入密码：")
                sex = input("请输入性别：")
                yh[name] = passward
                xb[name] = sex
                print("注册成功，请登录")
                print("登录界面".center(100, "*"))
                while 1:
                    username = input("请输入用户名：")
                    if username in yh:
                        while 1:
                            userpwd = input("请输入密码：")
                            if userpwd == yh[username]:
                                print("登录成功")
                                break
                            else:
                                print("密码错误")
                        break
                    else:
                        print("用户名不存在，请重新输入")
                break
            elif int(xz) == 2:
                print("登录界面".center(100, "*"))
                while 1:
                    username = input("请输入用户名：")
                    if username in yh:
                        while 1:
                            userpwd = input("请输入密码：")
                            if userpwd == yh[username]:
                                print("登录成功")
                                break
                            else:
                                print("密码错误")
                        break
                    else:
                        print("用户名不存在，请重新输入")
                break
            else:
                print("请正确选择")
        except:
                print("请正确选择")
    while 1:
        try:
            ys = int(input("请输入购物预算信息,必须为数字："))
            break
        except:
            print("请输入数字")
    while 1:
        print("输入4查看商品信息，输入5查看已购买信息,输入6进行购买操作")
        ck = input("请选择：")
        if int(ck) == 4:
            print("商品展示".center(100, "*"))
            for bh, j in goods.items():
                print("编号:", bh, end=' ')
                print("商品名称：", j['gname'], end=' ')
                print("商品价格：", j['price'], end=' ')
                print("库存：", j['kc'])
            ex(input("输入exit可退出系统，任意按钮继续："))
        elif int(ck) == 5:
            print("已购商品信息".center(100, "*"))
            for bh, j in ygsp.items():
                print("编号:", bh, end=' ')
                print("商品名称：", j['gname'], end=' ')
                print("商品价格：", j['price'], end=' ')
                print("已购数量：", j['account'])
        elif int(ck) == 6:
            print("购买界面".center(100, "*"))
            a = input("请输入你要购买的商品编号：")
            b = goods[a]
            #ygsp[a] = b
            if int(ys) > b['price']:
                if a in ygsp:
                    c = ygsp[a]
                    c['account'] = int(c['account'])+int(1)
                    b['kc'] = int(b['kc'])-int(1)
                else:
                    ls = ls + 1
                    b['account'] = ls
                    b['kc'] = int(b['kc']) - int(1)
                    ygsp[a] = b
                ys = float(ys) - float(b['price'])
                print("购买成功")
                print("余额还有：", ys)
                ex(input("输入exit可退出系统："))
            else:
                print("余额不足")
        elif int(ck) == 7:
            print("已退出登录")
            break
        else:
            pass